<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;

/**
 * 用户签到表
 */
class UserSign extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];


    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\common\model\UserSign();

    }

    /**
     * 签到
     */
    public function sign()
    {
        $res = $this->model->makeSign($this->auth->id);

        if ($res['code'] = 1) {
            //签到送积分
            $this->model->giveUserScore($this->auth->id);
            $this->success('',$res['msg']);

        } else {
            $this->error('',$res['msg']);
        }
    }

    public function signPage()
    {

        $isSignToday = $this->model->isSignToday($this->auth->id);

        $signCount = Db::name('user_sign')->where(['user_id' => $this->auth->id])->value('count');

        $signScore = Db::name('config')->where(['name' => 'sign_score'])->value('value');

        $this->success('',[
            'isSignToday' => $isSignToday,
            'signCount' => $signCount ? $signCount : 0,
            'signScore' => $signScore ? $signScore : 0
        ]);

    }
}